| Conditions | 6 |
| Total Lines | 139 |
| Code Lines | 86 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | // jshint esversion: 8, -W069 |
||
| 86 | function isDomainAvailable(resultsText, resultsJSON) { |
||
| 87 | const { |
||
| 88 | 'lookup.assumptions': assumptions |
||
| 89 | } = settings; |
||
| 90 | |||
| 91 | resultsJSON = resultsJSON || 0; |
||
| 92 | |||
| 93 | if (resultsJSON === 0) resultsJSON = toJSON(resultsText); |
||
| 94 | |||
| 95 | var domainParams = getDomainParameters(null, null, null, resultsJSON, true); |
||
| 96 | var controlDate = getDate(Date.now()); |
||
| 97 | |||
| 98 | switch (true) { |
||
| 99 | /* |
||
| 100 | Special cases |
||
| 101 | */ |
||
| 102 | case (resultsText.includes('Uniregistry') && resultsText.includes('Query limit exceeded')): |
||
| 103 | return (assumptions.uniregistry ? 'unavailable' : 'error:ratelimiting'); |
||
| 104 | |||
| 105 | /* |
||
| 106 | Available checks |
||
| 107 | */ |
||
| 108 | |||
| 109 | // Not found cases & variants |
||
| 110 | //case (resultsText.includes('ERROR:101: no entries found')): |
||
| 111 | |||
| 112 | |||
| 113 | // No match cases & variants |
||
| 114 | case (resultsText.includes('No match for domain')): |
||
| 115 | case (resultsText.includes('- No Match')): |
||
| 116 | case (resultsText.includes('NO MATCH:')): |
||
| 117 | case (resultsText.includes('No match for')): |
||
| 118 | case (resultsText.includes('No match')): |
||
| 119 | case (resultsText.includes('No matching record.')): |
||
| 120 | case (resultsText.includes('Nincs talalat')): |
||
| 121 | |||
| 122 | // Status cases & variants |
||
| 123 | case (resultsText.includes('Status: AVAILABLE')): |
||
| 124 | case (resultsText.includes('Status: AVAILABLE')): |
||
| 125 | case (resultsText.includes('Status: available')): |
||
| 126 | case (resultsText.includes('Status: free')): |
||
| 127 | case (resultsText.includes('Status: Not Registered')): |
||
| 128 | case (resultsText.includes('query_status: 220 Available')): |
||
| 129 | |||
| 130 | // Unique cases |
||
| 131 | case (domainParams.expiryDate - controlDate < 0): |
||
| 132 | case (resultsText.includes('This domain name has not been registered')): |
||
| 133 | case (resultsText.includes('The domain has not been registered')): |
||
| 134 | case (resultsText.includes('This query returned 0 objects')): |
||
| 135 | case (resultsText.includes(' is free') && domainParams.whoisreply.length < 50): |
||
| 136 | case (resultsText.includes('domain name not known in')): |
||
| 137 | case (resultsText.includes('registration status: available')): |
||
| 138 | case (resultsText.includes('whois.nic.bo') && domainParams.whoisreply.length < 55): |
||
| 139 | case (resultsText.includes('Object does not exist')): |
||
| 140 | case (resultsText.includes('The queried object does not exist')): |
||
| 141 | case (resultsText.includes('Not Registered -')): |
||
| 142 | case (resultsText.includes('is available for registration')): |
||
| 143 | case (resultsText.includes('is available for purchase')): |
||
| 144 | case (resultsText.includes('DOMAIN IS NOT A REGISTERD')): |
||
| 145 | case (resultsText.includes('No such domain')): |
||
| 146 | case (resultsText.includes('No_Se_Encontro_El_Objeto')): |
||
| 147 | case (resultsText.includes('Domain unknown')): |
||
| 148 | case (resultsText.includes('No information available about domain name')): |
||
| 149 | case (resultsText.includes('Error.') && resultsText.includes('SaudiNIC')): |
||
| 150 | case (resultsText.includes('is not valid!')): // ??? |
||
| 151 | return 'available'; |
||
| 152 | |||
| 153 | /* |
||
| 154 | Unavailable checks |
||
| 155 | */ |
||
| 156 | case (resultsJSON.hasOwnProperty('domainName')): // Has domain name |
||
| 157 | case (resultsText.includes('Domain Status:ok')): // Domain name is ok |
||
| 158 | case (resultsText.includes('Expiration Date:')): // Has expiration date (1) |
||
| 159 | case (resultsText.includes('Expiry Date:')): // Has Expiration date (2) |
||
| 160 | case (resultsText.includes('Status: connect')): // Has connect status |
||
| 161 | case (resultsText.includes('Changed:')): // Has a changed date |
||
| 162 | case (Object.keys(resultsJSON).length > 5): // JSON has more than 5 keys (probably taken?) |
||
| 163 | case (resultsText.includes('organisation: Internet Assigned Numbers Authority')): // Is controlled by IANA |
||
| 164 | return 'unavailable'; |
||
| 165 | |||
| 166 | /* |
||
| 167 | Error checks |
||
| 168 | */ |
||
| 169 | |||
| 170 | // Error, null or no contents |
||
| 171 | case (resultsText === null): |
||
| 172 | case (resultsText === ''): |
||
| 173 | return 'error:nocontent'; |
||
| 174 | |||
| 175 | // Error, unauthorized |
||
| 176 | case (resultsText.includes('You are not authorized to access or query our Whois')): |
||
| 177 | return 'error:unauthorized'; |
||
| 178 | |||
| 179 | // Error, rate limiting |
||
| 180 | case (resultsText.includes('IP Address Has Reached Rate Limit')): |
||
| 181 | case (resultsText.includes('Too many connection attempts')): |
||
| 182 | case (resultsText.includes('Your request is being rate limited')): |
||
| 183 | case (resultsText.includes('Your query is too often.')): |
||
| 184 | case (resultsText.includes('Your connection limit exceeded.')): |
||
| 185 | return (assumptions.ratelimit ? 'unavailable' : 'error:ratelimiting'); |
||
| 186 | |||
| 187 | // Error, unretrivable |
||
| 188 | case (resultsText.includes('Could not retrieve Whois data')): |
||
| 189 | return 'error:unretrivable'; |
||
| 190 | |||
| 191 | // Error, forbidden |
||
| 192 | case (resultsText.includes('si is forbidden')): // .si is forbidden |
||
| 193 | case (resultsText.includes('Requests of this client are not permitted')): // .ch forbidden |
||
| 194 | return 'error:forbidden'; |
||
| 195 | |||
| 196 | // Error, reserved by regulator |
||
| 197 | case (resultsText.includes('reserved by aeDA Regulator')): // Reserved for aeDA regulator |
||
| 198 | return 'error:reservedbyregulator'; |
||
| 199 | |||
| 200 | // Error, unregistrable. |
||
| 201 | case (resultsText.includes('third-level domains may not start with')): |
||
| 202 | return 'error:unregistrable'; |
||
| 203 | |||
| 204 | // Error, reply error |
||
| 205 | case (resultsJSON.hasOwnProperty('error')): |
||
| 206 | case (resultsJSON.hasOwnProperty('errno')): |
||
| 207 | case (resultsText.includes('error ')): |
||
| 208 | case (resultsText.includes('error')): // includes plain error, may cause false negatives? i.e. error.com lookup |
||
| 209 | case (resultsText.includes('Error')): // includes plain error, may cause false negatives? i.e. error.com lookup |
||
| 210 | case (resultsText.includes('ERROR:101:')): |
||
| 211 | case (resultsText.includes('Whois lookup error')): |
||
| 212 | case (resultsText.includes('can temporarily not be answered')): |
||
| 213 | case (resultsText.includes('Invalid input')): |
||
| 214 | return 'error:replyerror'; |
||
| 215 | |||
| 216 | /* |
||
| 217 | Error throw |
||
| 218 | If every check fails throw Error, unparsable |
||
| 219 | */ |
||
| 220 | |||
| 221 | default: |
||
| 222 | return (assumptions.unparsable ? 'available' : 'error:unparsable'); |
||
| 223 | } |
||
| 224 | } |
||
| 225 | |||
| 404 |